-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update http proxy to handle client disconnect scenario #10688
Conversation
For the scenarios you tested, can you compare how this would behave in a regular AspNetCore app? I think we should align with that behavior as best we can. If client disconnects, is an exception thrown? Is the request considered failed or successful? |
Here's what I found using a plain aspnet app: RequestAborted
CancellationTokenSource cancelled
Here's the app I used, or do you think I need to try and replicate what we're doing with the YARP as well? var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/process", async (HttpContext context) =>
{
var cancellationToken = context.RequestAborted; // Client disconnect
// var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(5)).Token; // Cancel after 5 seconds
try
{
// Simulate some work that can be cancelled
Console.WriteLine("Starting work...");
for (int i = 0; i < 10; i++)
{
// Simulate work
await Task.Delay(1000, cancellationToken);
Console.WriteLine($"Work iteration {i + 1} completed.");
}
Console.WriteLine("Work completed.");
context.Response.StatusCode = StatusCodes.Status200OK;
await context.Response.WriteAsync("Processing completed successfully.");
}
catch (OperationCanceledException)
{
Console.WriteLine("Request was cancelled.");
context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest; // Status code for client closed request
await context.Response.WriteAsync("Request was cancelled.");
}
});
app.Run(); |
Don't need to test with YARP directly, but I would like us to compare with your found results for AspNetCore with what happens in the functions YARP scenario today. Also: |
@jviau In comparison, here is the result to the exact same code as above but in a function app with what we have today in dev: RequestAborted
CancellationTokenSource cancelled
And with my changes in this PR:RequestAborted
CancellationTokenSource cancelled
|
Issue describing the changes in this PR
resolves #10600
Pull request checklist
IMPORTANT: Currently, changes must be backported to the
in-proc
branch to be included in Core Tools and non-Flex deployments.in-proc
branch is not requiredrelease_notes.md
Additional information
HandleCancellationMiddleware
to returnStatus499ClientClosedRequest
on client disconnectRetryProxyHandler
to stop retries when the request is cancelledTesting
See comments below for test scenarios completed. Behaviour change from this PR have been compared to a) what is in dev today and b) what aspnet does